﻿#region Using Directives

    using System;
    using System.Collections.Generic;
    using System.Linq;

    using Csla;

    using MarketPulse.BusinessLogic.Core;
    using MarketPulse.BusinessLogic.Common.Criteria;

#endregion

namespace MarketPulse.BusinessLogic.Common
{
    /// <summary>
    /// This class represents a collection of read-only EnquiryReasons
    /// </summary>
    [Serializable]
    [Csla.Server.ObjectFactory("MarketPulse.DataAccess.Factory.EnquiryFactory, MarketPulse.DataAccess.Factory", "FetchReasonInfoList")]
    public class EnquiryReasonInfoList : MarketPulseReadOnlyListBase<EnquiryReasonInfoList, EnquiryReasonInfo>
    {
        #region Constructors

            /// <summary>
            /// Default constructor is private in order to (try to) enforce construction
            /// only via the static factory methods provided.
            /// </summary>
            private EnquiryReasonInfoList()
            {
            }

        #endregion

        #region Methods

            #region Factory Methods

                ///// <summary>
                ///// Method used to get a read only list of read only EnquiryReasons that are associated with a particular EnquiryType (via the DataPortal client proxy)
                ///// </summary>
                ///// <param name="enquiryTypeGuid">The EnquiryType Guid used to retrieve the EnquiryReasonInfo list</param>
                ///// <returns>A populated read only list of read only EnquiryReasons</returns>
                //public static EnquiryReasonInfoList GetByEnquiryTypeGUID(Guid enquiryTypeGuid)
                //{
                //    return DataPortal.Fetch<EnquiryReasonInfoList>(new EnquiryTypeGUIDCriteria(enquiryTypeGuid));
                //}

                /// <summary>
                /// Method used to get a read only list of read only EnquiryReasons that are associated with a particular Client (via the DataPortal client proxy)
                /// </summary>
                /// <param name="clientGuid">The guid of the client to retrieve this list for</param>
                /// <returns>A valid (populated) list of EnquiryReason objects</returns>
                public static EnquiryReasonInfoList GetByClientGUID(Guid clientGuid)
                {
                   return DataPortal.Fetch<EnquiryReasonInfoList>(new SingleCriteria<Guid>(clientGuid));
                }

            #endregion

            /// <summary>
            /// Method used to find a single EnquiryReasonInfo object from the collection based on the unique identifier supplied
            /// </summary>
            /// <param name="enquiryReasonGuid">The guid that uniquely identifies the EnquiryReasonInfo object to find</param>
            /// <returns>A populated EnquiryReasonInfo object</returns>
            public EnquiryReasonInfo FindByGuid(Guid enquiryReasonGuid)
            {
                var result = (from reason in this.Items
                              where reason.GUID == enquiryReasonGuid
                              select reason).Single();

                return (EnquiryReasonInfo)result;
            }

            /// <summary>
            /// Method used to find all EnquiryReasonInfo objects from the collection based on the enquiry type guid supplied
            /// </summary>
            /// <param name="enquiryTypeGuid">The guid of the EnquiryType to use as part of the search</param>
            /// <returns>A populated EnquiryTypeInfoList object</returns>
            public IList<EnquiryReasonInfo> FindByTypeGuid(Guid enquiryTypeGuid)
            {
                var result = (from reason in this.Items
                              where reason.EnquiryTypeGUID == enquiryTypeGuid
                              select reason).ToList();

                return (IList<EnquiryReasonInfo>)result;
            }

        #endregion
    }
}
